﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Library.Extensions;

namespace Script
{
    internal class GetLineCount
    {
        public GetLineCount()
        {
            do
            {
                var folder = SystemConsole.GetInputStr("请拖入文件夹：");
                if (!Directory.Exists(folder))
                    continue;
                var ex = SystemConsole.GetInputStr("请输入文件后缀(如\"cs,cpp\"：");
                if (string.IsNullOrEmpty(folder))
                    continue;
                var hash = new HashSet<string>(ex.Split(','), StringComparer.OrdinalIgnoreCase);
                var files = Directory.EnumerateFiles(folder, "*.*", SearchOption.AllDirectories).Where(p => hash.Contains(Path.GetExtension(p))).ToArray();
                File.WriteAllLines(ex + ".txt", files);
                Console.WriteLine("总行数：" + files.Sum(p => File.ReadAllLines(p).Length));
            } while (SystemConsole.ContinueY());
        }
    }
}
